home *** CD-ROM | disk | FTP | other *** search
- import java.awt.BorderLayout;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.Dialog;
- import java.awt.Dimension;
- import java.awt.Graphics;
- import java.awt.Point;
- import java.awt.Toolkit;
- import java.awt.Window;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.KeyEvent;
- import java.awt.event.KeyListener;
- import javax.swing.AbstractButton;
- import javax.swing.ImageIcon;
- import javax.swing.JButton;
- import javax.swing.JCheckBox;
- import javax.swing.JComponent;
- import javax.swing.JDialog;
- import javax.swing.JLabel;
- import javax.swing.JPanel;
- import javax.swing.JScrollPane;
- import javax.swing.JTextArea;
- import javax.swing.border.EmptyBorder;
- import javax.swing.border.MatteBorder;
-
- public class ChannelManager extends JDialog implements ActionListener, KeyListener {
- protected ChannelList database = new ChannelList();
- protected int selectedItem = 0;
- protected JButton updateButton = new JButton(new ImageIcon("newsmac.app/contents/resources/update-channel.gif"));
- protected JLabel categoryIcon = new JLabel(new ImageIcon());
- protected JLabel channelName = new JLabel();
- protected JTextArea channelDescription = new JTextArea();
- protected JScrollPane scrollArea = new JScrollPane(20, 31);
- protected Config theConfig;
- protected Container main = new Container();
- protected NewsMac parent;
-
- public ChannelManager(NewsMac theParent, Config conf) {
- super(theParent, "Channel Manager", true);
- this.parent = theParent;
- this.database = this.parent.theEngine.getChannels();
- this.theConfig = conf;
- Toolkit theKit = ((Window)this).getToolkit();
- int width = 530;
- int height = 388;
- int xPos = (int)(new Dimension(theKit.getScreenSize())).getWidth() / 2 - width / 2;
- ((Component)this).setBounds(xPos, 160, width, height);
- ((Dialog)this).setResizable(false);
- JLabel columnHeaders = new JLabel(new ImageIcon("newsmac.app/contents/resources/columns.jpg"));
- ((Component)columnHeaders).setBounds(20, 20, width - 40, 21);
- this.scrollArea.setBounds(20, 39, 490, 236);
- this.scrollArea.setBorder(new MatteBorder(0, 1, 1, 1, new Color(150, 150, 150)));
- this.scrollArea.setViewportView(this.channelList(this.database));
- this.categoryIcon.setBounds(20, 287, 32, 32);
- this.channelName = AquaUtil.aquaSmallBoldLabel(60, 289, "No channel selected", 2);
- this.channelDescription.setBounds(60, 305, 246, 42);
- this.channelDescription.setFont(AquaUtil.SMALL_SYSTEM);
- this.channelDescription.setText("");
- this.channelDescription.setOpaque(false);
- this.channelDescription.setEditable(false);
- this.channelDescription.setLineWrap(true);
- this.channelDescription.setWrapStyleWord(true);
- this.channelDescription.setBorder(new EmptyBorder(0, 0, 0, 0));
- this.updateButton.setBounds(448, 288, 64, 64);
- this.updateButton.setVerticalAlignment(0);
- this.updateButton.setHorizontalAlignment(0);
- this.updateButton.setVerticalTextPosition(3);
- this.updateButton.setHorizontalTextPosition(0);
- this.updateButton.setText("Update");
- this.updateButton.setEnabled(true);
- this.updateButton.addActionListener(this);
- this.main.add(columnHeaders);
- this.main.add(this.scrollArea);
- this.main.add(this.categoryIcon);
- this.main.add(this.channelName);
- this.main.add(this.channelDescription);
- this.main.add(this.updateButton);
- ((JDialog)this).getContentPane().add(this.main);
- ((Component)this).addKeyListener(this);
- this.updateChannelInfo(this.database.getChannel(0));
- }
-
- protected JPanel channelList(ChannelList theList) {
- JPanel temp = new JPanel(new BorderLayout());
- Container holder = new Container();
- int y = 0;
-
- for(int i = 0; i < theList.size(); ++i) {
- if (i == this.selectedItem) {
- holder.add(this.row(0, y, i, theList.getChannel(i), true));
- } else {
- holder.add(this.row(0, y, i, theList.getChannel(i), false));
- }
-
- y += 20;
- }
-
- ((Component)holder).setBounds(0, 0, 450, y);
- ((JComponent)temp).setBackground(new Color(255, 255, 255));
- ((JComponent)temp).setBorder(new EmptyBorder(0, 0, 0, 0));
- ((Container)temp).add(holder, "Center");
- ((JComponent)temp).setPreferredSize(new Dimension(((Component)holder).getWidth(), ((Component)holder).getHeight()));
- return temp;
- }
-
- protected Container row(int x, int y, int n, Channel theChannel, boolean selected) {
- Container temp = new Container();
- JButton bg = new JButton();
- JCheckBox on = new JCheckBox();
- JLabel channelName = AquaUtil.aquaSmallLabel(54, 3, theChannel.getName(), 2);
- JLabel version = AquaUtil.aquaSmallLabel(440, 3, "" + theChannel.getVersion(), 2);
- JLabel cat = AquaUtil.aquaSmallLabel(296, 3, Channel.CATEGORY[theChannel.getCategory()], 2);
- ((Component)bg).setBounds(0, 0, 480, 20);
- ((JComponent)bg).setBorder(new EmptyBorder(0, 0, 0, 0));
- ((AbstractButton)bg).setActionCommand(theChannel.getName());
- ((AbstractButton)bg).addActionListener(this);
- if (selected) {
- ((JComponent)bg).setBackground(Config.SELECTION_COLOUR);
- ((JComponent)channelName).setForeground(new Color(255, 255, 255));
- ((JComponent)version).setForeground(new Color(255, 255, 255));
- ((JComponent)cat).setForeground(new Color(255, 255, 255));
- } else if (n % 2 == 0) {
- ((JComponent)bg).setBackground(new Color(255, 255, 255));
- } else {
- ((JComponent)bg).setBackground(new Color(239, 247, 255));
- }
-
- ((AbstractButton)on).setSelected(theChannel.isOn());
- ((Component)on).setBounds(16, 1, 18, 18);
- ((JComponent)on).setOpaque(false);
- ((AbstractButton)on).setActionCommand(theChannel.getName() + "on");
- ((AbstractButton)on).addActionListener(this);
- temp.add(on);
- temp.add(channelName);
- temp.add(version);
- temp.add(cat);
- temp.add(bg);
- ((Component)temp).setBounds(x, y, 480, 20);
- return temp;
- }
-
- private void updateChannelInfo(Channel theChannel) {
- this.channelName.setText(theChannel.getName());
- String[] channelIcon = new String[]{"toolbar-mynews.gif", "toolbar-macnews.gif", "toolbar-specialist.gif", "toolbar-industry.gif", "toolbar-world.gif"};
- this.categoryIcon.setIcon(new ImageIcon("newsmac.app/contents/resources/" + channelIcon[theChannel.getCategory()]));
- String temp = theChannel.getDescription();
- if (temp.length() > 128) {
- temp = temp.substring(0, 104) + "...";
- }
-
- this.channelDescription.setText(temp);
- }
-
- public void paint(Graphics g) {
- super.paint(g);
- }
-
- public static void main(String[] args) {
- }
-
- public void keyTyped(KeyEvent kv) {
- }
-
- public void keyReleased(KeyEvent kv) {
- }
-
- public void keyPressed(KeyEvent kv) {
- int key = kv.getKeyCode();
- if (key == 40) {
- if (this.selectedItem < this.database.size() - 1) {
- ++this.selectedItem;
- }
-
- Point old = this.scrollArea.getViewport().getViewPosition();
- if (old.getY() + (double)20.0F <= (double)this.scrollArea.getViewport().getView().getHeight()) {
- old.setLocation(old.getX(), old.getY() + (double)20.0F);
- }
-
- this.scrollArea.setViewportView(this.channelList(this.database));
- this.scrollArea.getViewport().setViewPosition(old);
- this.updateChannelInfo(this.database.getChannel(this.selectedItem));
- }
-
- if (key == 38) {
- if (this.selectedItem > 0) {
- --this.selectedItem;
- }
-
- Point old = this.scrollArea.getViewport().getViewPosition();
- if (old.getY() - (double)20.0F >= (double)0.0F) {
- old.setLocation(old.getX(), old.getY() - (double)20.0F);
- }
-
- this.scrollArea.setViewportView(this.channelList(this.database));
- this.scrollArea.getViewport().setViewPosition(old);
- this.updateChannelInfo(this.database.getChannel(this.selectedItem));
- }
-
- }
-
- public void actionPerformed(ActionEvent newEvent) {
- String buttonString = newEvent.getActionCommand();
- if (buttonString.equals("Update")) {
- this.updateButton.setEnabled(false);
- this.updateButton.setDisabledIcon(new ImageIcon("newsmac.app/contents/resources/updating.gif"));
-
- try {
- Thread checkChannels = new Updater(this.parent, this);
- checkChannels.start();
- } catch (Exception var5) {
- System.out.println("ChannelManager: " + var5);
- }
- }
-
- if (!buttonString.equals("")) {
- for(int i = 0; i < this.database.size(); ++i) {
- if (buttonString.equals(this.database.getChannel(i).getName())) {
- this.selectedItem = i;
- Point old = this.scrollArea.getViewport().getViewPosition();
- this.scrollArea.setViewportView(this.channelList(this.database));
- this.scrollArea.getViewport().setViewPosition(old);
- this.updateChannelInfo(this.database.getChannel(i));
- }
-
- if (buttonString.equals(this.database.getChannel(i).getName() + "on")) {
- if (this.database.getChannel(i).isOn()) {
- this.database.getChannel(i).setOn(false);
- } else {
- this.database.getChannel(i).setOn(true);
- }
- }
- }
- }
-
- }
- }
-